package com.xc.quickstart.api.controller;


import com.xc.quickstart.api.query.LoginQuery;
import com.xc.quickstart.api.vo.UserInfoVO;
import com.xc.quickstart.common.annotation.GlobalApiResponse;
import com.xc.quickstart.common.annotation.Token;
import com.xc.quickstart.service.LoginBizService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RequestMapping(method = {RequestMethod.POST, RequestMethod.GET})
@Slf4j
@RestController
@Api(description = "登录接口业务", tags = "login")
@GlobalApiResponse
public class LoginApiController {

    @Autowired
    private LoginBizService loginBizService;

    @ApiOperation(value = "获取验证码", notes = "获取验证码")
    @RequestMapping(value = "common/get_sms_code")
    public String getSmsCode(@ApiParam("mobile") String mobile) {
        return loginBizService.getSmsCode(mobile);
    }

    @ApiOperation(value = "登录", notes = "登录")
    @RequestMapping(value = "common/code_login")
    public UserInfoVO loginWithSmsCode(@RequestBody @Validated LoginQuery loginQuery) {
        return loginBizService.loginWithSmsCode(loginQuery);
    }

    @ApiOperation(value = "获取用户信息", notes = "获取用户信息")
    @RequestMapping(value = "common/check_login")
    @Token
    public UserInfoVO getUserInfo() {
        return loginBizService.getUserInfo();
    }

    @ApiOperation(value = "企业微信授权登陆", notes = "企业微信授权登陆")
    @RequestMapping(value = "common/auth_login")
    public UserInfoVO qyWechatLogin(@RequestParam(value = "code") String authorizationCode) {
        return loginBizService.qyWechatLogin(authorizationCode);
    }

}
